$(document).ready(function(){
	 $("#userData").show().siblings().hide();
   getYear();
});

$("#nav").click(function(event){
	var ev=event||window.event;
	var target=event.target||event.srcElement;
	// event.preventDefault();
  $(target).addClass('onClick');
  $(target).siblings().removeClass('onClick');
	if(target.innerHTML == "用户管理"){

		$("#userData").show().siblings().hide();
	}else if(target.innerHTML == "留言板管理"){
		$("#messageData").show().siblings().hide();
	}
  else if(target.innerHTML == "课程管理"){
		$("#sectionData").show().siblings().hide();
	}
}); 

$("#student_grid").bootstrapTable({
	url:"/studentController/query",//获取表格数据的url
	cache:false, // 设置为 false 禁用 AJAX 数据缓存， 默认为true
	striped: true,  //表格显示条纹，默认为false
    pagination: true, // 在表格底部显示分页组件，默认false
    pageList: [5,10,15,20], // 设置页面可以显示的数据条数
    pageSize: 10, // 页面数据条数
    pageNumber: 1, // 首页页码
    clickToSelect:true,//设置true 将在点击行时，自动选择rediobox 和 checkbox
    sidePagination: 'client', // 设置为客户端进行分页，即根据上面pageSize属性进行分页，若根据服务器进行分页(server),则将分页的数据通过参数传递
    sortName: 'stId', // 要排序的字段
    ortOrder: 'desc', // 排序规则
    showRefresh:true,
    uniqueId:'stId',
    columns: [
          {
              checkbox: true, // 显示一个勾选框
              align: 'center' // 居中显示
          }, {
              field: 'stId', // 要显示数据的字段名称，可以理解为json对象里的key
              title: '编号', // 表格表头显示文字
              align: 'center', // 左右居中
              valign: 'middle', // 上下居中
              visible: false
          }, {
              field: 'stName',
              title: '用户名称',
              width: 130,
              align: 'center',
              valign: 'middle'
          }, {
              field: 'stNickname',
              title: '用户昵称',
              align: 'center',
              width: 130,
              valign: 'middle'
          },{
              field: 'stSex',
              title: '性别',
              align: 'center',
              valign: 'middle',
          }, {
              field: 'stTel',
              title: '电话号码',
              align: 'center',
              width: 160,
              valign: 'middle'
          }, {
              field: 'stSchool',
              title: '学校',
              align: 'center',
              width: 180,
              valign: 'middle'
          }, {
              field: 'stMajor',
              title: '专业',
              align: 'center',
              width: 160,
              valign: 'middle'
          }, {
              field: 'stGrade',
              title: '年级',
              align: 'center',
              valign: 'middle'
          }, {
              field: 'stNumber',
              title: '学号',
              align: 'center',
              width: 160,
              valign: 'middle'
          }, 
          {
              title: "操作",
              align: 'center',
              valign: 'middle',
              width: 100, // 定义列的宽度，单位为像素px
              formatter: function (value, row, index) {
                  row.type="student";
                  return '<button class="btn btn-info btn-sm" data-toggle="modal" data-target="#textModal" onclick=" edit(\'' + row.stId + '\',\''+row.type+'\') ">修改</button>';
              }
          }
      ],
      onLoadSuccess: function(){  //加载成功时执行
            console.info("加载成功");
      },
      onLoadError: function(){  //加载失败时执行
            console.info("加载数据失败");
      }


});

$("#teacher_grid").bootstrapTable({
	url:"/teacherController/queryAllTeacher",
	cache:false, 
	striped: true,
    pagination: true, 
    pageList: [10, 20],
    pageSize: 10,
    pageNumber: 1, 
    clickToSelect:true,
    sidePagination: 'client', 
    sortName: 'tId', 
    ortOrder: 'desc', 
    showRefresh:true,
    uniqueId:'tId',
    columns: [
          {
              checkbox: true, 
              align: 'center' 
          }, {
              field: 'tId', 
              title: '编号',
              align: 'center', 
              valign: 'middle',
              visible: false
          }, {
              field: 'tName',
              title: '用户名',
              align: 'center',
              width: 160,
              valign: 'middle'
          }, {
              field: 'tNickname',
              title: '用户昵称',
              align: 'center',
              width: 160,
              valign: 'middle'
          }, {
              field: 'tSex',
              title: '性别',
              align: 'center',
              valign: 'middle',
          }, {
              field: 'tTel',
              title: '电话号码',
              align: 'center',
              width: 160,
              valign: 'middle'
          }, {
              title: "操作",
              align: 'center',
              valign: 'middle',
              width: 160, 
              formatter: function (value, row, index) {
                row.type="teacher";
                  return '<button class="btn btn-info btn-sm" data-toggle="modal" data-target="#textModal" onclick="edit(\'' + row.tId + '\',\''+row.type+'\')">修改</button>';
              }
          }
      ],
      onLoadError: function(){ 
            //alert("加载teacher数据失败");
      }
});

$("#user_grid").bootstrapTable({
	url:"/userController/qryAllLoginData",
	cache:false, 
	striped: true,  
    pagination: true, 
    pageList: [10, 20],
    pageSize: 10, 
    pageNumber: 1, 
    clickToSelect:true,
    sidePagination: 'client',
    sortName: 'id',
    ortOrder: 'desc', 
    uniqueId:'id',
    showRefresh:true,
    columns: [
          {
              checkbox: true, 
              align: 'center' 
          }, {
              field: 'id', 
              title: '用户id', 
              align: 'center', 
              valign: 'middle', 
              visible: false
          }, {
              field: 'userId', 
              title: '用户id', 
              align: 'center', 
              width:160,
              valign: 'middle', 
          }, {
              field: 'userName', 
              title: '用户名', 
              align: 'center',
              valign: 'middle' 
          }, {
              field: 'userNickname', 
              title: '用户昵称', 
              align: 'center',
              width:160,
              valign: 'middle' 
          },{
              field: 'userType',
              title: '用户类型',
              align: 'center',
              width:160,
              valign: 'middle',
          }, {
              field: 'loginnum',
              title: '登陆次数',
              align: 'center',
              valign: 'middle',
              formatter: function (value, row, index){ // 单元格格式化函数
                  return value + "次";
              } 
          }, {
              field: 'logintime',
              title: '最新登录时间',
              align: 'center',
              valign: 'middle',
              formatter: function (value, row, index){ // 单元格格式化函数
                  var date=new Date(value);
                  return date.getFullYear() + '-' +(date.getMonth()+1) + "-" + date.getDate() + " " +date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
              } 
          }
      ],
      onLoadError: function(){  
            console.info("加载数据失败");
      }
});

$("#message_grid").bootstrapTable({
  url:"/messageController/queryAllMessage",
  cache:false, 
  striped: true, 
    pagination: true, 
    pageList: [5, 10, 15],
    pageSize: 10,
    pageNumber: 1,
    clickToSelect:true,
    sidePagination: 'client',
    sortName: 'msId',
    ortOrder: 'desc',
    showRefresh:true, 
    uniqueId:'msId',
    columns: [
                {
                    checkbox: true, 
                    align: 'center' 
                }, {
                    field: 'msId', 
                    title: '留言id',
                    align: 'center', 
                    valign: 'middle', 
                    visible: false
                }, {
                    field: 'seId', 
                    title: '章节id', 
                    align: 'center', 
                    valign: 'middle', 
                    visible: false
                }, {
                    field: 'section.seName', 
                    title: '章节名称', 
                    align: 'center', 
                    valign: 'middle', 
                }, {
                    field: 'userId', 
                    title: '用户id', 
                    align: 'center', 
                    valign: 'middle', 
                    visible: false
                },{
                    field: 'userType',
                    title: '用户类型',
                    align: 'center',
                    valign: 'middle'
                },{
                    field: 'mName',
                    title: '用户名称',
                    align: 'center',
                    valign: 'middle'
                },{
                    field: 'mNickname',
                    title: '用户昵称',
                    align: 'center',
                    width: 100,
                    valign: 'middle'
                },{
                    field: 'msContent',
                    title: '留言内容',
                    align: 'center',
                    width: 270,
                    valign: 'middle'
                },{
                    field: 'msReleasetime',
                    title: '发表时间',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index){ // 单元格格式化函数
                        var date=new Date(value);
                        return date.getFullYear() + '-' +(date.getMonth()+1) + "-" + date.getDate() + " " +date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
                    } 
                },{
                    field: 'msModifytime',
                    title: '修改时间',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index){ // 单元格格式化函数
                        var date=new Date(value);
                        return date.getFullYear() + '-' +(date.getMonth()+1) + "-" + date.getDate() + " " +date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
                    } 
                }, {
                    title: "查看评论",
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                        return '<button class="btn btn-default btn-sm" onclick="queryComment(\'' + row.msId + '\')"><span class="glyphicon glyphicon-list-alt"></span></button>';
                    }
                }
        ],
        onLoadError: function(){ 
            console.info("加载数据失败");
        }
});

function queryComment(msId){
  $("#commentTab .btn-groups").removeClass('hidden');
  $("#comment_grid").bootstrapTable('destroy');
  $("#comment_grid").bootstrapTable({//todo
    url:"/commentController/queryCommentBymsId",
    cache:false,
    contentType : "application/x-www-form-urlencoded",
    striped: true, 
        pagination: true, 
        pageList: [5, 10, 15], 
        pageSize: 10,
        pageNumber: 1,
        clickToSelect:true,
        sidePagination: 'client',
        showRefresh:true,
        uniqueId:'commentId',
        sortName: 'commentId', 
        ortOrder: 'desc', 
        queryParams: function (params) { 
            return {
                msId: msId
            }
        }, 
        columns: [
            {
                checkbox: true, 
                align: 'center'
            }, {
                field: 'commentId', 
                title: '评论id', 
                align: 'center', 
                valign: 'middle',
                visible: false
            }, {
                field: 'msId', 
                title: '留言id',
                align: 'center', 
                valign: 'middle', 
                visible: false
            },{
                field: 'userId',
                title: '用户id',
                align: 'center',
                valign: 'middle',
                visible: false
            }, {
                field: 'commentUserType', 
                title: '用户类型',
                align: 'center', 
                valign: 'middle' 
            }, {
                field: 'cName', 
                title: '用户名称',
                align: 'center', 
                valign: 'middle' 
            },{
                field: 'cNickname',
                title: '用户昵称',
                align: 'center',
                width: 100,
                valign: 'middle'
            },{
                field: 'commentContent',
                title: '评论内容',
                align: 'center',
                width: 270,
                valign: 'middle'
            },{
                field: 'commentReleasetime',
                title: '发表时间',
                align: 'center',
                valign: 'middle',
                width: 150,
                formatter: function (value, row, index){ // 单元格格式化函数
                    var date=new Date(value);
                    return date.getFullYear() + '-' +(date.getMonth()+1) + "-" + date.getDate() + " " +date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
                } 
            },{
                field: 'commentModifytime',
                title: '修改时间',
                align: 'center',
                valign: 'middle',
                width: 150,
                formatter: function (value, row, index){ // 单元格格式化函数
                    var date=new Date(value);
                    return date.getFullYear() + '-' +(date.getMonth()+1) + "-" + date.getDate() + " " +date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
                } 
            }
        ],
        formatNoMatches: function(){
            return "该留言没有评论";
        }
  });
}

function add(type){
    $("#textModal form input[name='name']").removeAttr('disabled');
    $("#editSubmit").addClass('hidden');
    $("#addSubmit").removeClass('hidden');
    resetForm();
    if(type=="student"){
        $("#textModal form input[name='type']").val("student");
        $("#textModal .modal-title").html("添加学生");
        var arr=$("#textModal form .form-control").filter(".form-control[name='school'],.form-control[name='major'],.form-control[name='number'],.form-control[name='grade']");
        arr.each(function(index, el) {
            $(el).parent().removeClass('hidden');
        });
    }else if(type=="teacher"){
        $("#textModal form input[name='type']").val("teacher");
        $("#textModal .modal-title").html("添加教师");
        var arr=$("#textModal form .form-control").filter(".form-control[name='school'],.form-control[name='major'],.form-control[name='number'],.form-control[name='grade']");
        arr.each(function(index, el) {
            $(el).parent().addClass('hidden');
        });
    }
}

function resetForm(){
    $("form input").each(function(index, el) {
        $(this).parent().find('.alarm').remove();
        $(this).parent().find('.tel').remove();
        if($(el).attr('type')!="radio"){
            $(el).val("");
        }
    });
}

// function delOne(id){
//     id=parseInt(id);
//     if(confirm("确定删除选中数据吗？")){
//         $.ajax({
//             url: '/studentController/delete',
//             type: 'post',
//             dataType : "json",
//             contentType : "application/json;charset=utf-8",
//             data: JSON.stringify({
//                 stId:id
//             }),
//             success:function(data){
//                 if(data==1){
//                     alert("删除学生成功！");
//                 }else{
//                     alert("删除学生失败！");
//                 }
//             }
//         });
//     }
// }

function del(type){
    var $gird,id;
    var url="";
    if(type=='student'){
        $gird=$("#student_grid");
        url="/studentController/deleteMulti";
        id="stId";
    }else if(type=='teacher'){
        $gird=$("#teacher_grid");
        url="/teacherController/deleteMulti";
        id="tId";
    }else if(type=='logindata'){
        $gird=$("#user_grid");
        url="/userController/delete";
        id="id";
    }
    var arr=$gird.bootstrapTable('getSelections');
    var idArr=[];
    if(arr.length==0){
        alert("请至少选一行数据");
    }else{
        if(confirm("确定删除选中数据吗？")){
            for (var i = 0; i < arr.length; i++) {
                idArr.push(arr[i][id]);
            }
            $.ajax({
                url: url,
                type: 'post',
                dataType : "json",
                contentType : "application/json;charset=utf-8",
                data: JSON.stringify(idArr),
                success:function(data){
                    if(data==1){
                        alert("删除成功！");
                    }else{
                        alert("删除失败！");
                    }
                }
            });
        } 
    }
}

function delMessage(type){
    var $gird,id;
    var url="";
    if(type=='message'){
        $gird=$("#message_grid");
        url="/messageController/deleteMessages";
        id="msId";
    }else if(type=='comment'){
        $gird=$("#comment_grid");
        url="/commentController/deleteComments";
        id="commentId";
    }
    var arr=$gird.bootstrapTable('getSelections');
    var idArr=[];
    if(arr.length==0){
        alert("请至少选一行数据");
    }else{
        if(confirm("确定删除选中数据吗？")){
            for (var i = 0; i < arr.length; i++) {
                idArr.push(arr[i][id]);
            }
            $.ajax({
                url: url,
                type: 'post',
                dataType : "json",
                contentType : "application/json;charset=utf-8",
                data: JSON.stringify(idArr),
                success:function(data){
                    if(data==1){
                        alert("删除成功！");

                    }else{
                        alert("删除失败！");
                    }
                    $gird.bootstrapTable('refresh');
                    if($gird[0].id=="message_grid"){
                        $("#comment_grid").bootstrapTable('refresh');
                    }
                }
            });
        } 
    }
}

function edit(id,type){
  var $gird,rowData;
  $("#addSubmit").addClass('hidden'); 
  $("#editSubmit").removeClass('hidden'); 
  if(type=='student'){
    $gird=$("#student_grid");
    $("#textModal form input[name='type']").val("student");
    rowData=$gird.bootstrapTable('getRowByUniqueId',id);
    var arr=$("#textModal form .form-control").filter(".form-control[name='school'],.form-control[name='major'],.form-control[name='number'],.form-control[name='grade']");
    arr.each(function(index, el) {
      $(el).parent().removeClass('hidden');
    });
    $("#textModal .modal-title").html("学生信息修改");
    $("#textModal form input[name='id']").val(id);
    $("#textModal form input[name='name']").val(rowData.stName);
    $("#textModal form input[name='nickname']").val(rowData.stNickname);
    $("#textModal form input[name='password']").val(rowData.stPassword);
    $("#textModal form select[name='sex']").val(rowData.stSex);
    $("#textModal form input[name='tel']").val(rowData.stTel);
    $("#textModal form input[name='school']").val(rowData.stSchool);
    $("#textModal form input[name='major']").val(rowData.stMajor);
    $("#textModal form input[name='number']").val(rowData.stNumber);
    $("#textModal form select[name='grade']").val(rowData.stGrade);
  }else if(type=='teacher'){
    $gird=$("#teacher_grid");
    $("#textModal .modal-title").html("教师信息修改");
    $("#textModal form input[name='type']").val("teacher");
    rowData=$gird.bootstrapTable('getRowByUniqueId',id);
    var arr=$("#textModal form .form-control").filter(".form-control[name='school'],.form-control[name='major'],.form-control[name='number'],.form-control[name='grade']");
    arr.each(function(index, el) {
      $(el).parent().addClass('hidden');
    });
    $("#textModal .modal-title").html("学生信息修改");
    $("#textModal form input[name='id']").val(id);
    $("#textModal form input[name='name']").val(rowData.tName);
    $("#textModal form input[name='nickname']").val(rowData.tNickname);
    $("#textModal form input[name='password']").val(rowData.tPassword);
    $("#textModal form select[name='sex']").val(rowData.tSex);
    $("#textModal form input[name='tel']").val(rowData.tTel);
  }
  $("#textModal form input[name='name']").attr("disabled","disabled");
}


function isNull(modal){

  $(" "+modal+" form :input.required").each(function(){
    var obj=$(this).parent().find('.alarm');
    if($(this).val()==""){
      if(obj.length==0){
        $(this).parent().append("<b style='color:red' class='alarm'>X该字段不能为空!</b>");
      }
    }else{
      $(this).parent().find('.alarm').remove();
    }
  })
  var arr=$(" "+modal+" form .form-group:not(.hidden)").find(".required").filter(function(index) {
    return $(this).val()=="";
  });
  if(arr.length!=0){
    alert("请填入完整信息！");
    return false;
  }else{
    return true;
  }
}


/*验证代码-----start*/
$("#textModal form input[name='name']").blur(function(){
    var name=$("#textModal form input[name='name']").val();
    var type=$("#textModal form input[name='type']").val();
    $.ajax({
      url: '/userController/isExist',
      type: 'post',
      data: {
        name: name,
        type:type  
      },
      contentType : "application/x-www-form-urlencoded",
      success:function(data){
          if(data==1){
            alert("该用户名已存在");
            $("#textModal .btn-submit").attr('disabled',true);
          }else{
            $("#textModal .btn-submit").removeAttr('disabled');
          }
        }
    });
});

$("#textModal form input[name='tel']").blur(function(){
    var tel=$("#textModal form input[name='tel']").val();
    var pattern=/^1[34578]\d{9}$/;
    if(!(pattern.test(tel))){
      if($(this).parent().find(".tel").length==0){
        $(this).parent().append("<b style='color:red' class='tel'> X请输入正确的电话格式!</b>");
        $("#textModal .btn-submit").attr('disabled',true);
      }
    }else{
      $(this).parent().find(".tel").remove('.tel');
      $("#textModal .btn-submit").removeAttr('disabled');
    }
});

$("form :input.required:not(.hidden)").each(function(){
  $(this).parent().prepend("<strong style='color:red'>*</strong>");
})
/*验证代码----end*/

$(".logout").click(function(event) {
  var name=sessionStorage.getItem("name");
  if(confirm("确定退出登录吗？")){
    sessionStorage.removeItem("name");
    sessionStorage.removeItem("id");
    sessionStorage.removeItem("nickname");
    sessionStorage.removeItem("sex");
    sessionStorage.removeItem("tel");
    sessionStorage.removeItem("major");
    sessionStorage.removeItem("grade");
    sessionStorage.removeItem("school");
    sessionStorage.removeItem("role");
    sessionStorage.removeItem("password");
    alert("当前用户 "+name+" 已退出");
  }else{
    event.preventDefault();
  }
});

function addSubmit(){
  var url="";
  var type=$("#textModal form input[name='type']").val();
  if(type=="student"){
      url='/studentController/add';
  }else if(type=="teacher"){
      url='/teacherController/add';
  }
  var params={};
  params.name=$("#textModal form input[name='name']").val();
  params.nickname=$("#textModal form input[name='nickname']").val();
  params.password=$("#textModal form input[name='password']").val();
  params.sex=$("#textModal form select[name='sex']").val();
  params.tel=$("#textModal form input[name='tel']").val();
  params.school=$("#textModal form input[name='school']").val();
  params.major=$("#textModal form input[name='major']").val();
  params.number=$("#textModal form input[name='number']").val();
  params.grade=$("#textModal form select[name='grade']").val();
  if(isNull("#textModal")){
    $.ajax({
      url: url,
      type: 'post',
      dataType : "json",
      contentType : "application/json;charset=utf-8",
      data: JSON.stringify(params),
      success:function(data){
        if(data==1){
          alert("添加成功！");
          resetForm();
        }else{
          alert("添加失败！");
        }
      }
    });
    $("#textModal").modal('hide');
  }
}

function editSubmit(){
  var url="";
  var type=$("#textModal form input[name='type']").val();
  if(type=="student"){
      url='/studentController/editStudent';
  }else if(type=="teacher"){
      url='/teacherController/editTeacher';
  }
  var params={};
  params.id=$("#textModal form input[name='id']").val();
  params.nickname=$("#textModal form input[name='nickname']").val();
  params.password=$("#textModal form input[name='password']").val();
  params.sex=$("#textModal form select[name='sex']").val();
  params.tel=$("#textModal form input[name='tel']").val();
  params.school=$("#textModal form input[name='school']").val();
  params.major=$("#textModal form input[name='major']").val();
  params.number=$("#textModal form input[name='number']").val();
  params.grade=$("#textModal form select[name='grade']").val();
  $.ajax({
    url: url,
    type: 'post',
    dataType : "json",
    contentType : "application/json;charset=utf-8",
    data: JSON.stringify(params),
    success:function(data){
      if(data==1){
        alert("修改成功！");
        
      }else{
        alert("修改失败！");
      }
    }
  });
  $("#textModal").modal('hide');
}

function getYear(){
  var date=new Date();
  var year=date.getFullYear();
  for (var i =2010; i <=year; i++){
     $("select[name='grade']").append('<option>'+i+'</option>')
  }
 
}

$("#adminModal form :input[name='oldPassword']").blur(function(event) {
  var pwdVal=$(this).val();
  var name=sessionStorage.getItem("name");
  $.ajax({
    url: "/adminController/checkAdminPwd",
    type: 'POST',
    contentType : "application/x-www-form-urlencoded",
    data: {
      password: pwdVal,
      name: name
    },
    success: function(data){
      if(data.returnCode==1){
        $("#adminModal .btn-submit").removeAttr('disabled');
        $("#adminModal form :input[name='newPassword']").attr('disabled',false);
      }else if(data.returnCode==0){
        alert("原密码错误，请重新确定");
        $("#adminModal .btn-submit").attr('disabled',true);
        $("#adminModal form :input[name='newPassword']").attr('disabled',true);
      }
    }
  });
});

// 初始化admin个人信息数据
function initAdminInfo(){
    getAdminInfo();
    $("#adminModal form :input[name='id']").val(sessionStorage.getItem("id"));
    $("#adminModal form :input[name='name']").val(sessionStorage.getItem("name"));
    $("#adminModal form :input[name='name']").attr('disabled',true);
    $("#adminModal form :input[name='tel']").val(sessionStorage.getItem("tel"));
}

function getAdminInfo(){
    var name=sessionStorage.getItem("name");
    $.ajax({
        url: '/adminController/getAdminInfo',
        type: 'POST',
        dataType: ' json',
        data: {name: name},
        contentType : "application/x-www-form-urlencoded",
        success: function(data){
            if(data!=null){
                sessionStorage.setItem("tel",data.tel);
            }
        }
    });
    
}

$("#adminModal .btn-submit").click(function(event) {
    var params={};
    var newPwd=$("#adminModal form :input[name='newPassword']").val();
    params.id=$("#adminModal :input[name='id']").val();
    if($("#adminModal form :input[name='tel']").val()!=""){
        params.tel=$("#adminModal form :input[name='tel']").val();
    }
    if(newPwd!=""){
        params.password=newPwd;
    }
    $.ajax({
        url: '/adminController/editAdmin',
        type: 'post',
        dataType : "json",
        contentType : "application/json;charset=utf-8",
        data: JSON.stringify(params),
        success:function(data){
            if(data==1){
                alert("修改成功！");
                getAdminInfo();
                $("#adminModal").modal('hide');
            }else{
                alert("修改失败！");
            }
        }
    });
});

$("#adminModal form input[name='tel']").blur(function(){
    var tel=$("#adminModal form input[name='tel']").val();
    var pattern=/^1[34578]\d{9}$/;
    if(!(pattern.test(tel))){
      if($(this).parent().find(".tel").length==0){
        $(this).parent().append("<b style='color:red' class='tel'> X请输入正确的电话格式!</b>");
        $("#adminModal .btn-submit").attr('disabled',true);
      }
    }else{
      $(this).parent().find(".tel").remove('.tel');
      $("#adminModal .btn-submit").removeAttr('disabled');
    }
});

